<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="项目管理">
   <form id="searchForm" class="form-panel" action="${basepath}/rest/manage/contract/selectContractPage">
       <ul class="panel-content">
           <li>
               <div class="form-actions">
                   <div class="control-group controls span5">
                       <input type="text"  class="input-normal  input-pad" name="name" placeholder="请输入关键字搜索">
                   </div>
                   <div class="control-group controls select-group">
                       <label class="time-label control-label">选择筛选状态：</label>
                       <div class="time-controls controls" style="float: right;">
                           <select name="status" class="input-normal" id="status">
                               <option value="">筛选状态</option>
                               <option value="y">显示中</option>
                               <option value="n">隐藏中</option>
                           </select>
                       </div>
                   </div>
                   <div class="form-actions  controls">
                       <button type="submit" class="button  button-primary">
                           查询
                       </button>

                   </div>
                   <div class="contract-button">
                       <a class="button button-primary" onclick="return hideFunction()">
                           批量隐藏
                       </a>
                       <a class="button button-primary" onclick="return showFunction()">
                           批量显示
                       </a>
                   </div>

               </div>
           </li>
       </ul>
   </form>
    <div id="grid"></div>
<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title : '序号',elCls: 'center', dataIndex :'id', width:'10%',renderer:function (value, obj, index) {
                        return index+1;
                    }},
                {title : '客户名称',elCls: 'center',dataIndex :'customerName', width:'10%'},
                {title : '合同性质',elCls: 'center',dataIndex :'type', width:'10%'},
                {title : '合同名称',elCls: 'center',dataIndex :'name', width:'10%'},
                {title : '合同编号',elCls: 'center',dataIndex :'sno', width:'10%'},
                {title : '录入时间',elCls: 'center',dataIndex :'createTime',width:'15%'},
                {title : '当前状态',elCls: 'center',dataIndex :'status', width:'10%',renderer:function (value) {
                        return value=="y"?"显示":"隐藏"
                    }},
                {title : '操作时间',elCls: 'center',dataIndex :'updateTime', width:'15%'},
                {title : '操作',elCls: 'center',dataIndex : 'id',width:'10%',renderer : function (value,obj) {
                        return '<a href="javascript:editStatus(' +value+ ')">修改状态</a>';
                    }
                }
            ];

    var store = new Store({
                url : '/rest/manage/contract/selectContractPage',
                autoLoad:true, //自动加载数据
                params : { //配置初始请求的参数
                    length : '10',
                    status:$("#status").val()
                },
                pageSize:10,	// 配置分页数目
                root : 'list',
                totalProperty : 'total'
            }),
            grid = new Grid.Grid({
                render:'#grid',
                columns : columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar:{
                    pagingBar:true
                }
            });

    grid.render();
    /**********************模糊搜索*************************/
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /**********************修改状态*************************/
    function editStatus(value) {
        $.ajax({
            type: 'GET',
            url: '${basepath}/rest/manage/contract/selectDetail',
            dataType: 'json',
            data: {
                id: value
            },
            success: function (data) {
                var status=data.data.status;
                queryOneStatus(status,value)
            }
        });
    }
    function queryOneStatus(status,value) {
        BUI.Message.Confirm('是否执行该操作？', function () {
            $.ajax({
                type: 'POST',
                url: "${basepath}/rest/manage/contract/updateJson",
                dataType: 'json',
                data: {
                    id: value,
                    status:status=="y"?"n":"y"

                },
                success: function (data) {
                    var obj = form.serializeToObject();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }
    /**********************批量隐藏*************************/
    function hideFunction() {
        var selections = grid.getSelection();
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids[i] = selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/rest/manage/contract/updateStatus",
            dataType: "json",
            data: {
                ids: ids,
                status:'n'
            },
            success: function (data) {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });
    }
    /**********************批量显示*************************/
    function showFunction() {
        var selections = grid.getSelection();
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids[i] = selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/rest/manage/contract/updateStatus",
            dataType: "json",
            data: {
                ids: ids,
                status:'y'
            },
            success: function (data) {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });
    }
</script>

</@page.pageBase>
